<template>
	<view>
		<cu-custom :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">用户分组选择</block>
		</cu-custom>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" :up="upOption">
			<view v-for="(item,index) in dataList" :key="index">
				<view class="flex justify-between align-center padding bg-white solid-bottom" style="width: 100%;">
					<text class="text-df padding-right-sm">{{item.name}}</text>
					<button @tap="chooseGroup(item)" class="cu-btn bg-blue radius">选择</button>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import {
		getUserGroupList
	} from '@/api/api.js'
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				dataList: [],
				upOption: {
					use:false,
				}
			}
		},
		onLoad(options) {
			this.initGroupList()
		},
		methods: {
			downCallback() 
			{
				this.initGroupList()
			},
			chooseGroup(item) {
				const eventChannel = this.getOpenerEventChannel()
				eventChannel.emit('finishChoose', item);
				uni.navigateBack({
					delta: 1
				})
			},
			initGroupList() {
				uni.showLoading({
					title: '正在加载...'
				})
				getUserGroupList().then(res => {
					uni.hideLoading()
					this.dataList = res.data
					if (this.mescroll) {
						this.mescroll.endSuccess(res.data.length, false);
					}
				}).catch(error => {
					uni.hideLoading()
					if(this.mescroll) {
						this.mescroll.endErr()
					}
				})
			}
		},
	}
</script>

<style scoped>

</style>
